<?php
// 简单测试脚本
echo "开始测试...\n";

// 测试登录
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api/auth/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'username' => 'admin',
    'password' => '123456'
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "登录测试:\n";
echo "HTTP状态码: " . $httpCode . "\n";
echo "响应: " . $response . "\n\n";

$loginData = json_decode($response, true);
if ($loginData['code'] === 200) {
    $token = $loginData['data']['token'];
    echo "获取到Token: " . $token . "\n\n";
    
    // 测试获取外部API配置
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api/system-configs/external-api');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $token,
        'Content-Type: application/json'
    ]);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    echo "获取外部API配置测试:\n";
    echo "HTTP状态码: " . $httpCode . "\n";
    echo "响应: " . $response . "\n\n";
} else {
    echo "登录失败\n";
} 